package logger.sd.server.service;

import logger.sd.protocol.LRP;
import logger.sd.server.LoggingServer;

public class ServiceFactory {

	public static Service createService(String codeService, String message,
			String clientAddress, LoggingServer server) {

		Service service = initService(codeService, message, clientAddress,
				server);

		return service;
	}

	private static Service initService(String codeService, String message,
			String clientAddress, LoggingServer server) {

		if (codeService.equals(LRP.ECHO.getMessage())) {
			return new EchoService(message);
		} else if (codeService.equals(LRP.WAIT.getMessage())) {
			return new WaitService(server.getConfig());
		} else if (codeService.equals(LRP.LOG.getMessage())) {
			return new LoggingService(message, clientAddress,
					server.getConfig());
		} else if (codeService.equals(LRP.TOKEN.getMessage())) {
			return new TokenArriveService(message, server);
		}
		return null;
	}
}
